package com.zyf.service.web;


import com.zyf.service.convert.LocalMediaInfo;
import com.zyf.service.convert.M3u8ConvertorTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Description TODO
 * @Author lfp
 * @Version 1.0
 */
//@Api(tags = "视频转换")
@RestController
@RequestMapping("video")
public class VideoUploadController {

    @Autowired
    private M3u8ConvertorTemplate m3u8ConvertorTemplate;


    /**
    *@Description 通过指定本地路径，将本地视频转为 m3u8
    *@param mediaInfo
    *@Return
    */
//    @ApiOperation(value = "文件路径 转 m3u8",notes = "这种方式适合操作本机文件")
    @PostMapping("local/convert")
    public String transferToM3u8(@RequestBody LocalMediaInfo mediaInfo) throws IOException {
        LocalMediaInfo localMediaInfo = new LocalMediaInfo().setMediaPath(mediaInfo.getMediaPath());
        return m3u8ConvertorTemplate.localFileToM3u8(localMediaInfo);
    }

    /**
    *@Description 上传视频文件转m3u8
    *@param file 文件
    *@Return 
    */
//    @ApiOperation(value = "上传视频文件转m3u8",notes = "适用于服务器上传。服务器需要安装ffmpeg")
    @PostMapping("file/convert")
    public String streamToM3u8(@RequestPart("file") MultipartFile file) throws IOException {
        return m3u8ConvertorTemplate.mediaFileToM3u8(file);
    }
}